import Taro, { Component } from '@tarojs/taro'; 
import { Image } from '@tarojs/components'; 
import defaultIcon from '../../assets/images/common/defaultImg.png'
/**  * 组件需要的Props定义  */ 
// interface IProps {  
//     className: string;   
//     src: string; 
//     type: string;   
//     key: string;
// } 
export default class ImageCom extends Component {
    constructor(props) {
        super(props)
        this.state = {
            imgDefault: defaultIcon,
            trueAddress: ''
        };
    }
    componentDidMount() {
        // const {className} = this.props
        // let query = Taro.createSelectorQuery().in(this.$scope)
        // let el = query.select(`.${className}`)
        // el.boundingClientRect(rect=> {
        //     console.log(rect)
        //     if(rect){

        //     }
        // }).exec()

    }
    handleLoad(e) {
        this.setState({
            trueAddress: e.target.dataset.pic
        })
    }
    render() {         
        const { className, src, style, mode } = this.props         
        return (             
            <Image
                style={style}
                className={className}         
                src={trueAddress || this.state.imgDefault}
                mode={mode || 'widthFix'}  
                data-pic={src}
                onLoad={this.handleLoad.bind(this)}  
            />         
        );     
    } 
}
